/**
 * Created by 健旭 on 2014/12/13.
 */
var table;
var monitor = {};

function alarmPost(url, data, sucfun, timeout) {
    $.ajax({
        type: "post",
        timeout: timeout,
        data: data,
        url: url,
        success: sucfun,
        error: function (e, textStatus) {
            //showError(e);
        },
        complete: function (XMLHttpRequest, status) { //请求完成后最终执行参数
            if (status == 'timeout') {//超时,status还有success,error等值的情况
//                alert("超时");
            }
        }
    });
}

$(function () {
    $.alarmPost = alarmPost;
    // 提卡面值监控
    monitor.orderFaceEnter = function () {
        $.alarmPost("/MonitorController/getSupplyCardFace", {}, function (data) {
            var tb = document.getElementById("orderFaceTable");
            //删除原先数据，2 为保留表头，值为表头行数减1
            for (var n = tb.rows.length - 1; n >= 2; n--) {
                tb.deleteRow(n);
            }
            if(data==null||data.length<1){
                return
            }
            for (var i = 0; i < data.length; i++) {
                var row = tb.insertRow(tb.rows.length);
                //var c1 = row.insertCell(0);
                row.insertCell(0).innerHTML = data[i].operatorName;
                row.insertCell(1).innerHTML = data[i].area;
                row.insertCell(2).innerHTML = data[i].face;
                row.insertCell(3).innerHTML = data[i].total;
                row.insertCell(3).innerHTML = data[i].successCount;
                row.insertCell(3).innerHTML = data[i].failCount;
            }
        }, 3000);
        setTimeout('monitor.orderEnter()', 1000 * 30);
    };
    // 消耗速度监控
    monitor.orderEnter = function () {
        $.alarmPost("/MonitorController/getSupplyCardSpeed", {}, function (data) {
            var tb = document.getElementById("orderEnterTable");
            //删除原先数据，2 为保留表头，值为表头行数减1
            for (var n = tb.rows.length - 1; n >= 2; n--) {
                tb.deleteRow(n);
            }
            if(data==null||data.length<1){
                return
            }
            for (var i = 0; i < data.length; i++) {
                var row = tb.insertRow(tb.rows.length);
                //var c1 = row.insertCell(0);
                row.insertCell(0).innerHTML = productTypeConvert(data[i].productType);
                row.insertCell(1).innerHTML = data[i].area;
                row.insertCell(2).innerHTML = data[i].face;
                row.insertCell(3).innerHTML = data[i].oneMinute;
            }
        }, 3000);
        setTimeout('monitor.orderEnter()', 1000 * 30);
    };

    //提卡用户
    monitor.intervention = function () {
        $.alarmPost("/MonitorController/getSupplyCardUser", {}, function (data) {
            var tb = document.getElementById("interventionTable");
            for (var n = tb.rows.length - 1; n >= 2; n--) {
                tb.deleteRow(n);
            }
            var row = tb.insertRow(tb.rows.length);
            var amount = "<a href='javascript:void(0)' onclick='interventionInfo("+data.userIds+")' >" + data.newUserTotal + "</a>";
            row.insertCell(0).innerHTML = data.successUserTotal;
            row.insertCell(1).innerHTML = amount;
        }, 3000);
        setTimeout('monitor.intervention()', 1000 * 30);
    };
    monitor.orderFaceEnter();
    monitor.orderEnter();
    monitor.intervention();
});



//新增提卡用户详情
function interventionInfo(userIds) {
    console.log(userIds)
    addTab("/userList?userIds="+userIds,"1","新提卡用户列表")
}